package countdownlatch;

import java.util.concurrent.CountDownLatch;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-08-08
 * Time: 14:00
 */
//模拟三个孩子吃饺子的过程，母亲得等待三个孩子把饺子吃完再去洗碗
    //孩子吃完了就说自己吃完了
public class ChildThread1 extends Thread{
    private CountDownLatch countDownLatch;
    public ChildThread1(CountDownLatch countDownLatch) {
        this.countDownLatch=countDownLatch;
    }
    @Override
    public void run() {
        //1.吃饺子
        for(int i=1;i<=10;i++){
            System.out.println(getName()+"在吃第"+i+"个饺子");
        }
        //2.吃完说一声
        //每一次countDown方法的时候，就让计数器-1
        countDownLatch.countDown();
    }
}
